#include <iostream>
#include <unistd.h>
#include "RpcCommunicationFrame.hpp"

RpcReadConfFile RpcCommunicationFrame::_RpcReadConfFile;

void Uages() 
{

    std::cout << "Uages:" << std::endl; 
    std::cout << "      formal:./excutable -i RpcFileConf.txt" << std::endl; 
    std::cout << "      Before executing the executable file,you need to configure RpcFileConf.txt (located in the configurationfile directory)" << std::endl;
}

void RpcCommunicationFrame::ReadConfFlie(int argc,char** argv)
{
     _RpcReadConfFile.ReadConfFile(argc,argv);
}

void RpcCommunicationFrame::PrintAllConf()
{
     _RpcReadConfFile.PrintAllConf();
}


RpcCommunicationFrame &RpcCommunicationFrame::GetRpcCommunicationFrame()
{
    static RpcCommunicationFrame _RpcCommunicationFrame;
    return _RpcCommunicationFrame;
}

void RpcCommunicationFrame::Init(int argc,char** argv)
{
     if(argc != 3)
     {
        Uages();
        exit(EXIT_FAILURE); // 这是cpp的标准退出方式，就和那几个标准格式类型转化一样
     }

     int c = 0;
     std::string config_file;
     
     while( (c=getopt(argc,argv,"i:")) != -1)
     {
        switch (c)
        {
        case 'i':
            config_file = argv[2];
            break;
        case '?':        
            Uages();
            exit(EXIT_FAILURE);
            break;
        default :
            Uages();
            exit(EXIT_FAILURE);
            break;
        }
     }

     //最后的检查
     if(config_file != "RpcFileConf.txt")
     {
        Uages();
        exit(EXIT_FAILURE); 
     }
   
     GetRpcCommunicationFrame().ReadConfFlie(argc,argv);
}
